package com.sxt;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sxt.copy.Jsoup1;
import com.sxt.copy.Jsoup2;
import com.sxt.entity.Article;
import com.sxt.service.ArticleService;

public class jianshu {
    public static void add(String url){
    	 List<String> list = Jsoup2.addArticle(url, 
					"div.article h1", 
					"div.show-content");
 	//启动Spring容器
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
		ArticleService articleService=(ArticleService) context.getBean("articleService");
		Article art =new Article();
		
		String id =String.valueOf((int) (Math.random()*1000000000));
       art.setId(id);
       art.setTitle(list.get(0));
       art.setTags("区块链");
       art.setAuthorId("1533711302015");
       art.setContent(list.get(1));
       art.setCommentCount(0);
   	  art.setViewCount(0);
       art.setRewardContent("");
   	  art.setRewardPoint(0);
       art.setPermalink("/article/"+art.getId());
       Long l = System.currentTimeMillis();
        String date = l.toString();
   	  art.setCreateTime(new BigInteger(date));
       art.setUpdateTime(new BigInteger(date));
   	  art.setLatestCmtTime(new BigInteger("0"));
       art.setLatestCmterName("");
       art.setRandomDouble(Math.random());
       art.setCommentable("1");
      
       art.setEditorType(0);
       art.setArticleStatus(0);
   	  art.setArticleType(0);
       art.setGoodCnt(0);
   	  art.setBadCnt(0);
       art.setCollectCnt(0);
       art.setWatchCnt(0);
       art.setRedditScore(0d);
       art.setCity("");
       art.setIP("127.0.0.1");
       art.setUA("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0");
       art.setStick(new BigInteger("0"));
       art.setAnonymous(0);
       art.setPerfect(0);
       art.setAnonymousView(0);
       art.setAudioURL("");
       art.setQnAOfferPoint(0);
       art.setPushOrder(0);
		articleService.register(art);
  
    }
	public static void main(String[] args) throws Exception{
		List<String> urls = new ArrayList<String>();
		 urls.add("https://www.jianshu.com/p/093f6b276fda");
		
		 
		 for (String url : urls) {
			 add(url);
		}
     }
}
